/**
 * COPYRIGHT HangZhou 99Cloud Technology Company Limited
 * All right reserved.
 */
package com.zfsmart.projectdemo.account.service.impl;

import com.zfsmart.component.common.bean.restful.entity.ServiceException;
import com.zfsmart.projectdemo.account.entity.User;
import com.zfsmart.projectdemo.account.mapper.UserMapper;
import com.zfsmart.projectdemo.account.service.UserService;
import io.seata.core.context.RootContext;
import io.seata.core.exception.TransactionException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description
 * @Author 薛铁琪
 * @CreateTime 2021/8/2 11:16
 * @Version 1.0
 */
@Service
@Slf4j
public class Test {

    @Autowired
    UserService userService;
    @Autowired
    UserMapper userMapper;

    @Transactional
    public void doSomeThing3() throws InterruptedException, TransactionException {
        Thread.sleep(6000);
        userMapper.insert(User.builder().email("1").age(1).name("1").build());
        log.info(RootContext.getXID());

//        GlobalTransactionContext.reload(RootContext.getXID()).rollback();
//        int i = 1 / 0;
        throw new ServiceException("测试全局事务");
    }
}
